package com.kehutong.crm.app;

import com.kehutong.common.util.Token;
import com.kehutong.crm.entity.TrackRecord;
import org.coraframework.inject.Inject;
import org.coraframework.json.JSONObject;
import org.coraframework.mvc.MvcAction;
import org.coraframework.mvc.http.Bean;
import org.coraframework.mvc.http.ReqMapping;
import org.coraframework.mvc.http.result.Result;
import org.coraframework.orm.jdbc.JdbcSession;
import org.coraframework.orm.jdbc.Page;
import org.coraframework.util.Objects;


/**
 * 跟进记录
 *
 * @author: liukunlong
 * @date: 2021-03-06 14:15
 */
@MvcAction
@ReqMapping("/kht-bin/track/record")
public class TrackRecordAction {

    @Inject
    private JdbcSession jdbcSession;


    /**
     * 查看跟进记录
     * @param token
     * @param jsonObject
     * @return
     */
    @ReqMapping("/list")
    public Object getTrackRecordList(Token token, JSONObject jsonObject) {
        if (Objects.isNull(token)) {
            return Result.unlogin();
        }
        Page<TrackRecord> page = jdbcSession.findPage(TrackRecord.class)
                .eq(jsonObject, "id","residentNo","createBy")
                .like(jsonObject,"desc")
                .order("createTime", "desc")
                .page(jsonObject)
                .exe();
        return page;
    }


    /**
     * 保存住户跟进近路
     * @param token
     * @param trackRecord
     * @return
     * @throws Exception
     */
    @Bean(newInstance=true, copy=true)
    @ReqMapping("/save")
    public Object save(Token token,TrackRecord trackRecord) throws Exception {
        if (Objects.isNull(token)) {
            return Result.unlogin();
        }
        trackRecord.setCreateBy(token.getUuid());
        trackRecord.setCreateName(token.getUsername());
        jdbcSession.insert(trackRecord);
        return Result.success();
    }
}
